package com.sharp.authorization.holder;

import com.sharp.authorization.bo.account.AccountInfo;

/**
 * Title: AccountContextHolder
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2021/4/30 21:47
 */
public class AccountContextHolder {
    private static final ThreadLocal<AccountInfo> ACCOUNT_INFO_HOLDER = new ThreadLocal<>();

    private AccountContextHolder() {
    }

    public static void set(AccountInfo s) {
        ACCOUNT_INFO_HOLDER.set(s);
    }

    public static void remove() {
        if (ACCOUNT_INFO_HOLDER.get() != null) {
            ACCOUNT_INFO_HOLDER.remove();
        }
    }

    public static String getCurrentUserId() {
        return get().getOperator();
    }

    public static AccountInfo get() {
        return ACCOUNT_INFO_HOLDER.get();
    }
}
